﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PalmAddressExtractor
{
	public class Address
	{
		#region Fields

		private List<string> _phoneNumbers;
		private List<string> _customData;

		#endregion

		#region Properties

		public string LastName { get; set; }
		public string FirstName { get; set; }
		public string Title { get; set; }
		public string CompanyName { get; set; }

		public List<string> PhoneNumbers
		{
			get { return _phoneNumbers ?? (_phoneNumbers = new List<string>(5)); }
			set { _phoneNumbers = value; }
		}

		public string Street { get; set; }
		public string City { get; set; }
		public string State { get; set; }
		public string Zip { get; set; }
		public string Country { get; set; }
		public string Note { get; set; }

		public Category Category { get; set; }

		public List<string> CustomData
		{
			get { return _customData ?? (_customData = new List<string>(4)); }
			set { _customData = value; }
		}

		#endregion

		#region Methods

		public static string GetDelimitedHeaders(string delimiter)
		{
			var headers = string.Format("Last Name{0}First Name{0}Title{0}Company Name{0}Phone 1{0}Phone 2{0}Phone 3{0}Phone 4{0}Phone 5{0}Street{0}City{0}State{0}Zip{0}Country{0}Note{0}Category{0}Custom 1{0}Custom 2{0}Custom 3{0}Custom 4", delimiter);

			return headers;
		}

		public string ToDelimitedString(string delimiter)
		{
			var address = string.Format("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}{0}{9}{0}{10}{0}{11}{0}{12}{0}{13}", delimiter, LastName, FirstName, Title, CompanyName, string.Join(delimiter, PhoneNumbers), Street, City, State, Zip, Country, Note, Category != null ? Category.LongName : "No Category", string.Join(delimiter, CustomData));

			return address;
		}

		#endregion
	}
}
